package com.wyb.service.impl;

import com.wyb.mapper.CommentMapper;
import com.wyb.pojo.Comment;
import com.wyb.constant.Result;
import com.wyb.service.ReadAllService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReadAllServiceImpl implements ReadAllService {

    @Autowired
    private CommentMapper commentMapper;

    @Override
    public Result isReadAll(int userId) {
        List<Comment> comments = commentMapper.selectReplyByUserId(userId);
        if(!comments.isEmpty()){
            int count = 0;
            for (Comment comment : comments) {
                int i = commentMapper.updateReply(comment.getId());
                count += i;
            }
            return new Result(200, "全部已读成功,共已读"+count+"条", null);
        }
        return new Result(201, "全部已读失败", null);
    }
}
